package com.example.vue20220402.controller;


import com.example.vue20220402.pojo.Power;
import com.example.vue20220402.pojo.Usersinfo;
import com.example.vue20220402.service.IPowerService;
import com.example.vue20220402.vo.ResultData;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rock
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/power")
public class PowerController {

    @Resource
    IPowerService powerService;

    @RequestMapping("/list")
    public ResultData list(Power power){
        System.out.println(power.getPage());
        return powerService.list(power);
    }
    @RequestMapping("/updatePower")
    public ResultData updateUser(Power power){
        System.out.println(power);
        getPower(power);
//        power.setPowerIndex(power.getPowerParentid()==0?1:2);
//        //  =0 就是一级菜单   ！=0 二级菜单  把getPowerParentidval 赋值给 parentid
//        power.setPowerParentid(power.getPowerParentid()==0?0:power.getPowerParentidval());
//        power.setPowerOrder(1);
        return powerService.updatePower(power);
    }
    @RequestMapping("/deletePower")
    public ResultData deleteUser(Power power){
        System.out.println(power);
        return powerService.deletePower(power);
    }
    @RequestMapping("/addPower")
    public ResultData addPower(Power power){
        System.out.println(power);
        getPower(power);
        // =0 就是一级菜单  ！=0  就是二级菜单
//        power.setPowerIndex(power.getPowerParentid()==0?1:2);
//        //  =0 就是一级菜单   ！=0 二级菜单  把getPowerParentidval 赋值给 parentid
//        power.setPowerParentid(power.getPowerParentid()==0?0:power.getPowerParentidval());
//        power.setPowerOrder(1);
        return powerService.addPower(power);
    }
    private Power getPower(Power power){
        // =0 就是一级菜单  ！=0  就是二级菜单
        power.setPowerIndex(power.getPowerParentid()==0?1:2);
        //  =0 就是一级菜单   ！=0 二级菜单  把getPowerParentidval 赋值给 parentid
        power.setPowerParentid(power.getPowerParentid()==0?0:power.getPowerParentidval());
        power.setPowerOrder(1);
        return power;
    }
    @RequestMapping("/levellist")
    public ResultData levellist(Power power){
        System.out.println(power);
        return powerService.levellist(power);
    }
    @RequestMapping("/checklevellist")
    public ResultData checklevellist(Power power){
        System.out.println(power);
        return powerService.checklevellist(power);
    }



}

